package dao

import (
	"server/data/db"
	"server/public"
	"time"
)

/*
*  -*- coding:utf8 -*-
*
*   数据库操作相关
*
*  @Author  : chengms
*  @WebSite : chengms.com
*  @Email   : chengms2012@163.com
*  @TIME    : 2020/8/16 下午9:08
*  @File    : databaseOp.go
 */

func InitDatabase() {

	db.InitMysql()

	// isInit := true
	isInit := false
	if isInit {
		CreateInitDataTable()
		InsertInitInfo()
	}

}

func CreateInitDataTable() {
	var err error
	err = db.MysqlDb.CreateTable(UserInfoTable)

	err = db.MysqlDb.CreateTable(SysInfoTable)
	if err != nil {
		public.Loggerf.Errorf("Init Data failed: %v", err)
	}

}

func InsertInitInfo() {
	_, err := db.MysqlDb.Insert(InsertSysInfo, "v1.0", 100000, time.Now().Format("2006-01-02 15:04:05"))
	if err != nil {
		public.Loggerf.Errorf("Init Data failed: %v", err)
	}

	public.Loggerf.Infof("Init insert data successfully")
}
